package com.peaker.advertisingpro.view

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.view.Window
import com.peaker.advertisingpro.R
import com.peaker.advertisingpro.utils.Common
import com.peaker.advertisingpro.utils.SPUtil
import com.peaker.advertisingpro.utils.ToastUtils
import kotlinx.android.synthetic.main.layout_portset.*
import kotlinx.android.synthetic.main.qiyedialog.btn_back

/**
 *  @ 作者 CODE_LYF
 *  @ 时间   2021/3/18.
 *  代码人生
 */
class PortSetDialog(context: Context) : Dialog(context), View.OnClickListener {

    init {
        window?.requestFeature(Window.FEATURE_NO_TITLE)
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window?.setBackgroundDrawableResource(R.color.transparent)
        setContentView(R.layout.layout_portset)
        setCanceledOnTouchOutside(false)
        btn_back.setOnClickListener(this)
        btn_cancel.setOnClickListener(this)
        btn_save.setOnClickListener(this)
        et_port_set.setText(if (TextUtils.isEmpty(SPUtil.getSP(Common.WEB_PORT))) Common.web_port else SPUtil.getSP(Common.WEB_PORT))
        et_port2_set.setText(if (TextUtils.isEmpty(SPUtil.getSP(Common.MSG_PORT))) Common.msg_port else SPUtil.getSP(Common.MSG_PORT))

    }

    override fun onClick(v: View?) {
        when (v!!.id) {
            R.id.btn_back -> {
                dismiss()
            }
            R.id.btn_cancel -> {
                dismiss()
            }
            R.id.btn_save -> {
                SPUtil.putSP(Common.WEB_PORT, et_port_set.text.toString())
                SPUtil.putSP(Common.MSG_PORT, et_port2_set.text.toString())
                ToastUtils.s("端口保存成功")
                dismiss()
            }

        }


    }
}